﻿<!DOCTYPE html >
<html>

	<head>
		<meta name="Generator" content="tpshop" />
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width">
		<title>手机改绑</title>
		<meta http-equiv="keywords" content="用户注册-{$web_name}" />
		<meta name="description" content="用户注册-{$web_name}" />
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
		<link rel="stylesheet" type="text/css" href="/themes/wnsc_moblie/newMobile/User/login/css/public.css" />
		<link rel="stylesheet" type="text/css" href="/themes/wnsc_moblie/newMobile/User/login/css/login.css" />
		<script type="text/javascript" src="/themes/wnsc_moblie/newMobile/User/login/js/jquery.js"></script>
		<script src="/themes/wnsc_moblie/newMobile/User/login/js/global.js"></script>
		<script src="/themes/wnsc_moblie/newMobile/User/login/js/mobile_common.js"></script>
		<script type="text/javascript" src="/themes/wnsc_moblie/newMobile/User/login/js/mobile/layer.js"></script>
	</head>

	<body>
	<?php
				$agent = $_SERVER['HTTP_USER_AGENT'];
				if(strpos($agent,"Html5Plus") === false){
			?>
		<header id="header" class='header'>
			<div class="h-left">
				<a href="{:U('user/info')}" class="back"></a>
			</div>
			<div class="h-mid">手机改绑</div>
		</header>
	<?php
			}
			?>
		<div id="tbh5v0">
			<div class="log_reg_box">

				<div id="logRegTabCon">
					<div class="log_reg_item" id="phonearea">
						<form action="" method="post" id="mobileForm">
							<php>
								if($step==1){
							</php>
							<div class="field phone">
								<input type="text" id="username" name="username" placeholder="手机号" class="c-form-txt-normal" readonly value="{$user_info.phone}" style="background: #eee;"/>
							</div>

							<div class="yanzheng" style=" margin-top:0px;">
								<div class="codeTxt">
									<input type="text" id="mobile_code" name="mobile_code" placeholder="手机验证码" />
								</div>
								<div class="codePhoto">
									<input id="zphone" type="button" rel="mobile" value="获取手机验证码 " onClick="sendcode2(this)" class="zphone" style=" color:#FFF">
								</div>
							</div>
							<input type="button" id="btn_submit"  class="btn_big1" value="下一步" />
							<PHP>
								}
							    if($step==2){
							</php>
							<div >
								<div class="field phone">
									<input type="text" id="username" name="username" placeholder="新手机号" class="c-form-txt-normal" onBlur="checkMobilePhone(this.value);" />
									<div class="tips">
										<span id="mobile_phone_notice"></span>
									</div>
								</div>
								<div class="yanzheng" style=" margin-top:0px;">
									<div class="codeTxt">
										<input type="text" id="mobile_code" name="mobile_code" placeholder="手机验证码" />
									</div>
									<div class="codePhoto">
										<input id="zphone" type="button" rel="mobile" value="获取手机验证码 " onClick="sendcode(this)" class="zphone" style=" color:#FFF">
									</div>
								</div>
								<input type="button" id="btn_submit2"  class="btn_big1" value="立即改绑" />
							</div>
							<PHP>
								}
							</PHP>
						</form>
					</div>

				</div>
			</div>
		</div>
		<script type="text/javascript">
			setCurrentForm($("#mobileForm"));
			var flag = false;

			function changeForm(obj) {
				$(obj).removeClass('currr');
				$(obj).siblings().addClass('currr');
				if($(obj).attr('id') == 'mob_log') {
					$('#phonearea').show();
					setCurrentForm($("#mobileForm"))
					$('#emailarea').hide();
				} else {
					$('#phonearea').hide();
					setCurrentForm($("#emailForm"))
					$('#emailarea').show();
				}
			}

			function setCurrentForm(formObj) {
				currentForm = $(formObj);
			}

		

			function checkMobilePhone(mobile) {
				if(mobile == '') {
					$('#mobile_phone_notice').css('color', 'red');
					$('#mobile_phone_notice').html('* 手机号码不能为空');
					flag = false;
				} else if(checkMobile(mobile)) {

					$.ajax({
						type: "GET",
						url: "/user/register_validate2", //+tab,
						data: {
							mobile: mobile
						}, 
						success: function(data) {
							if(data.code == '0') {
								$('#mobile_phone_notice').css('color', 'green');
								$('#mobile_phone_notice').html('* 可以绑定');
								flag = true;
							} 
							
							if(data.code == '1') {
								$('#mobile_phone_notice').css('color', 'red');
								$('#mobile_phone_notice').html('* 手机号已存在');
								flag = false;
							}
							 
						}
					});
				} else {
					$('#mobile_phone_notice').css('color', 'red');
					$('#mobile_phone_notice').html('* 手机号码格式不正确');
					flag = false;
				}
			}




			$(function(){
				$('#btn_submit').click(function(){
					var username = $.trim($(currentForm).find('#username').val());
					var mobile_code = $(currentForm).find('#mobile_code').val();
					if(mobile_code) {
					$.ajax({
						url: '/user/change_phone_yz',
						type: 'post',
						dataType: 'json',
						data: {
							mobile: username,
							sms_captcha: mobile_code,
						},
						success: function(result) {
							if(result.code==0){
								layer.open({
									content: result.msg,
									time: 1
								});
							}
							if(result.code==1){
								layer.open({
									content: result.msg,
									time: 1
								});
								setTimeout('location.href="/user/change_phone.html";',1500)
							}
						}
					})
						
					} else {
						return false;
					}
				})

                $('#btn_submit2').click(function(){
                    var username = $.trim($(currentForm).find('#username').val());
                    var mobile_code = $(currentForm).find('#mobile_code').val();
                    if(mobile_code) {
                        $.ajax({
                            url: '/user/change_phone_yzbd',
                            type: 'post',
                            dataType: 'json',
                            data: {
                                mobile: username,
                                sms_captcha: mobile_code,
                            },
                            success: function(result) {
                                if(result.code==0){
                                    layer.open({
                                        content: result.msg,
                                        time: 1
                                    });
                                }
                                if(result.code==1){
                                    layer.open({
                                        content: result.msg,
                                        time: 1
                                    });
                                    setTimeout('location.href="/user/info.html";',1500)
                                }
                            }
                        })

                    } else {
                        return false;
                    }
                })
			})
			

			function sendcode(o) {

				if(flag) {

					$.ajax({
						url: '/user/sms_captcha2',
						type: 'post',
						dataType: 'json',
						data: {
							type: $(o).attr('rel'),
							send: $.trim($(currentForm).find('#username').val()),
							scene: 1
						},
						success: function(res) {
							console.log(res)
							if(res.code == 0) {
								layer.open({
									content: res.message,
									time: 1
								});

							} else {
								layer.open({
									content: res.message,
									time: 2
								});
                                countdown(o);
							}
						}
					})
				}
			}

            function sendcode2(o) {

                    $.ajax({
                        url: '/user/sms_captcha2',
                        type: 'post',
                        dataType: 'json',
                        data: {
                            type: $(o).attr('rel'),
                            send: $.trim($(currentForm).find('#username').val()),
                            scene: 1
                        },
                        success: function(res) {
                            console.log(res)
                            if(res.code == 0) {
                                layer.open({
                                    content: res.message,
                                    time: 1
                                });

                            } else {
                                layer.open({
                                    content: res.message,
                                    time: 2
                                });
                                countdown(o);
                            }
                        }
                    })
                }


			var wait = 150;

			function countdown(obj, msg) {
				obj = $(obj);
				if(wait == 0) {
					obj.removeAttr("disabled");
					obj.val(msg);
					wait = 150;
				} else {
					if(msg == undefined || msg == null) {
						msg = obj.val();
					}
					obj.attr("disabled", "disabled");
					obj.val(wait + "秒后重新获取");
					wait--;
					setTimeout(function() {
						countdown(obj, msg)
					}, 1000)
				}
			}
		</script>
	</body>

</html>